package service

import "gin-wheel/app/models"

type RegisterRequest struct {
	UserName string `form:"username" binding:"required,min=5,max=100"`
	PassWord string `form:"password" binding:"required,min=5,max=100"`
	Phone    string `form:"phone" binding:"required,min=11,max=11"`
	Email    string `form:"email" binding:"omitempty,email"`
	QQ       string `form:"qq" binding:"-"`
	Wechat   string `form:"wechat" binding:"-"`
}

type LoginParam struct {
	LoginName string `form:"loginname" binding:"required"`
	Password  string `form:"password" binding:"required"`
}

type RefreshTokenParam struct {
	RefreshToken string `form:"refresh_token" binding:"required"`
}

// 注册逻辑
func (svc *Service) Register(registerRequest RegisterRequest) (*models.UserModel, error) {
	um, err := svc.dao.Register(registerRequest.UserName, registerRequest.PassWord, registerRequest.Phone, registerRequest.Email, registerRequest.QQ, registerRequest.Wechat)
	if err != nil {
		return nil, err
	}
	return um, nil
}

// 获取用户 根据手机号或者用户名
func (svc *Service) UserInfo(username, phone string) (*models.UserModel, error) {
	um, err := svc.dao.UserInfo(username, phone)
	if err != nil {
		return nil, err
	}
	return um, nil
}

// 登录逻辑
func (svc *Service) Login(loginName, password string) (bool, error) {
	ok, err := svc.dao.Login(loginName, password)
	if err != nil {
		return false, err
	}
	return ok, err
}
